import vue from "@vitejs/plugin-vue";
import path from "path";
import { defineConfig, loadEnv } from "vite";
import { siconPlugin } from "sicon-plugin";

export default defineConfig(({ command, mode }) => {
    const dev = loadEnv(mode, process.cwd());
    const isBuild = command === "build";

    return {
        resolve: {
            alias: {
                "~/": `${path.resolve(__dirname, "src")}/`,
            },
        },
        css: {
            postcss: {
                plugins: [
                    {
                        postcssPlugin: "internal:charset-removal",
                        AtRule: {
                            charset: (atRule) => {
                                if (atRule.name === "charset") atRule.remove();
                            },
                        },
                    },
                ],
            },
        },
        plugins: [
            vue(),
            siconPlugin({
                isBuild,
                comUrl: "./src/components/sicon",
            }),
        ],
        server: {
            host: "0.0.0.0",
            port: 9011,
            open: false,
            https: false,
        },
    };
});
